<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<link rel="stylesheet" href="${ctx}/css/sapar.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/common.css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/sapar.js"></script>
<script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
<title>编辑菜单</title>
</head>

<body>
    <div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>编辑菜单</h2>
            </div>
			<div class="subfiled-content">
	            <form class="saper-form" id="dataForm">
	                <div class="kv-item clearfix">
	                    <label><span class="impInfo">*</span>菜单名称：</label>
	                    <div class="kv-item-content">
	                        <input type="text" placeholder="菜单名称" class="txt_required" name="moduleName" value="${module.moduleName}" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
	                    </div>
	                </div>
	                <div class="kv-item clearfix">
	                    <label><span class="impInfo">*</span>菜单类型：</label>
	                    <div class="kv-item-content">
	                    	<select class="txt_required" id="moduleType" name="moduleType">
	                    		 <option  value="">请选择</option>
	                          	 <option  value="1" <c:if test="${module.moduleType==1}">selected='selected'</c:if> >目录</option>
	                          	 <option  value="2" <c:if test="${module.moduleType==2}">selected='selected'</c:if> >菜单</option>
	                        </select>
	                    </div>
	                </div>
	                <div class="kv-item clearfix" >
	                    <label><span class="impInfo"></span>菜单地址：</label>
	                    <div class="kv-item-content">
	                        <input type="text" placeholder="菜单地址" name="moduleUrl" id="moduleUrl" value="${module.moduleUrl}" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
	                    </div>
	                </div>
					<div class="kv-item clearfix" >
	                    <label><span class="impInfo"></span>上级目录：</label>
	                    <div class="kv-item-content">
	                        <select class="" id="moduleParent" name="moduleParent">
	                        	 <option value="">请选择</option>
	                        	<c:forEach items="${moduleList}" var="mods">
	                          	 <option  value="${mods.moduleId}" <c:if test="${mods.moduleId==module.moduleParent}">selected='selected'</c:if> >${mods.moduleName}</option>
	                          	</c:forEach>  
	                        </select>
	                    </div>
	                </div>
	                <div class="kv-item clearfix" >
	                    <label><span class="impInfo"></span>菜单排序：</label>
	                    <div class="kv-item-content">
	                        <input type="text" placeholder="菜单排序" name="moduleOrder" id="moduleOrder" value="${module.moduleOrder}" />
	                    </div>
	                </div>
	                <div class="kv-item clearfix">
	                    <label><span class="impInfo">*</span>是否可用：</label>
	                    <div class="kv-item-content">
	                        <select class="empty" id="moduleIsover" name="moduleIsover">
	                          	 <option  value="1" <c:if test="${module.moduleIsover==1}">selected='selected'</c:if> >可用</option>
	                          	 <option  value="0" <c:if test="${module.moduleIsover==0}">selected='selected'</c:if> >不可用</option>
	                        </select>
	                    </div>
	                </div>
	                <div class="buttons">
	                    <a href="javascript:;" class="sapar-btn sapar-btn-recom">确定</a>
	                    <input name="moduleId" type="hidden" value="${module.moduleId}">
	                </div>
	            </form>
            </div>
        </div>
        <div id="saper-ft"></div>
    </div>
    
</body>

<script type="text/javascript">
function isNullOrEmpty(strVal){
	strVal = strVal.replace(/(^\s*)|(\s*$)/g,"");
	if(strVal == '' || strVal == null || strVal == undefined){
		return true;
	}else{
		return false;
	}
}
$(function(){
	$("#moduleType").change(function(){
		if($(this).val()==1){
			$("#moduleUrl").attr("class","");
			$("#moduleParent").attr("class","");
		}else if($(this).val()==2){
			$("#moduleUrl").attr("class","txt_required");
			$("#moduleParent").attr("class","txt_required");
		}
	});
	
	$(".sapar-btn-recom").click(function(){
		 var btn = true;
		 $(".txt_required").each(function(){
			 var str =$(this).val();
			 if(isNullOrEmpty(str)){
				 btn = false;
				 layer.msg("必填项不为空");
				 return false;
			 }
		 });
		 if(btn){
			 $.ajax({
	             type: "POST",
	             url:"${ctx}/url/moduleSave.do",
	             data:$('#dataForm').serialize(),// 你的formid
	             error: function(request) {
	            	 	layer.alert("网络故障，请稍后再试!");
	             },
	             success: function(data) {
	 	           	if(data.status=="true"){
		 	           	layer.alert("保存成功", function(){
		 	           		window.location.href="${ctx}/url/moduleList.do";
	           		    });
	 	           	}else{
	 	           		 layer.msg(data.msg);
	 	           	}
	             }
	         }); 
		 }
	});
});
</script>
</html>